#delimit;
clear all;
set more off;
set matsize 100;

graph set window fontface "Times New Roman";
graph set window fontfacesans "Times New Roman";
graph set window fontfaceserif "Times New Roman";
graph set window fontfacemono "Times New Roman";
graph set window fontfacesymbol "Times New Roman";

local root="/Users/lwdavis/Dropbox/Clean Energy Tax Credits/stata/adoption/";
cd "`root'";


*--------------------------------------------------------*;
*----------------------Heat Pumps------------------------*;
*--------------------------------------------------------*;
*Copy/paste annual heat pump shipments from AHRI website;
*Air Conditioning, Heating, and Refrigeration Institute;
*https://www.ahrinet.org/analytics/statistics/historical-data/central-air-conditioners-and-air-source-heat-pumps
clear; input year ashp;
2003 1626365; 2004 1886100; 2005 2136525; 2006 2118469;
2007 1898905; 2008 1865310; 2009 1642064; 2010 1747920;
2011 1765002; 2012 1697796; 2013 1968632; 2014 2353990;
2015 2269196; 2016 2429867; 2017 2619782; 2018 2920080;
2019 3110888; 2020 3418478; 2021 3916766; 2022 4334479;
2023 3616632; end; sort year;

display (3616632-4334479)/4334479;

*Shipments in Millions;
replace ashp=ashp/1000000;

*Recent Annual Heat Pump Shipments for Blog Post;
local color="dkorange";
scatter ashp year if year>=2009, title("")
  mcolor(black) msize(large) msymbol(oh) 
  connect(l) lcolor(black) lwidth(thin)
  xtitle("") xscale(range(2024)) xlabel(2009(2)2023, nogrid labsize(medium))
  ytitle("U.S. Heat Pump Shipments (in Millions)", size(medium)) 
  yscale(range(0)) ylabel(0(1)5, nogrid angle(0) labsize(medium)) 
  legend(off) plotregion(style(none)) graphregion(fcolor(white))
  text(2.75 2022 "U.S. Shipments", size(medium) color(`color'))
  text(2.50 2022 "Decrease By 16%", size(medium) color(`color'))
  text(2.25 2022 "in 2023", size(medium) color(`color'))
  || pcarrowi 3.00 2022 3.5 2022.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin);  

*Plot Heat Pump Shipments;
local color="dkorange";
scatter ashp year, title("")
  mcolor(black) msize(large) msymbol(oh) 
  connect(l) lcolor(black) lwidth(thin)
  xtitle("") xscale(range(2024)) xlabel(2003(4)2023, nogrid labsize(medium))
  ytitle("U.S. Heat Pump Shipments (in Millions)", size(medium)) 
  yscale(range(0)) ylabel(0(1)5, nogrid angle(0) labsize(medium)) 
  xscale(range(2002.5))
  legend(off) plotregion(style(none)) graphregion(fcolor(white))
  text(3.25 2004 "Tax Credit", size(small) color(`color'))
  text(3.00 2004 "Introduced", size(small) color(`color'))
  text(2.75 2004 "in 2006", size(small) color(`color'))
  text(1.00 2007 "Credit Not Available", size(small) color(`color'))
  text(0.75 2007 "During 2008", size(small) color(`color'))
  text(3.50 2009.5 "Credit Temporarily Increased", size(small) color(`color'))
  text(3.25 2009.5 "From 10% to 30%", size(small) color(`color'))
  text(3.00 2009.5 "During 2009 and 2010", size(small) color(`color'))
  text(4.00 2016.5 "Credit Not Available", size(small) color(`color'))
  text(3.75 2016.5 "During 2018", size(small) color(`color'))
  text(2.75 2022 "Credit Increased", size(small) color(`color'))
  text(2.50 2022 "From 10% to 30%", size(small) color(`color'))
  text(2.25 2022 "And Maximum Raised", size(small) color(`color'))
  text(2.00 2022 "From $300 to $2000", size(small) color(`color'))
  text(1.75 2022 "Starting 2023", size(small) color(`color'))
  || pcarrowi 2.60 2004.5 2.25 2005.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 1.25 2007 1.7 2007.7, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 2.75 2009.5 1.8 2009.1, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin) 
  || pcarrowi 2.75 2009.5 1.9 2009.9, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 3.50 2017.5 3.15 2017.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 3.00 2022 3.5 2022.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin);  
graph export "`root'/figs/HeatPumpShipments.pdf", as(pdf) replace;


*--------------------------------------------------------*;
*--------------------Rooftop Solar-----------------------*;
*--------------------------------------------------------*;
*Copy/paste annual residential solar installations from SEIA website;
*Solar Energy Industries Association, Solar Market Insight Report, Various Years
*http://www.seia.org/research-resources/us-solar-market-insight;
*Cumulative residential installations shown in figure on website and I took differences;
*https://www.seia.org/solar-industry-research-data;
clear; input year MW;
2000 1;    2001 5;    2002 11;   2003 15;   2004 24;   2005 27;   2006 38;   2007 58; 
2008 82;   2009 164;  2010 246;  2011 304;  2012 498;  2013 803;  2014 1272; 2015 2176;
2016 2643; 2017 2254; 2018 2416; 2019 2864; 2020 3246; 2021 4243; 2022 5976; 2023 6812;
end; sort year; 

*Installations in Gigawatts;
gen GW=MW/1000;

*Plot Residential Solar Installations;
local color="dkorange";
scatter GW year, title("")
  mcolor(black) msize(large) msymbol(oh) 
  connect(l) lcolor(black) lwidth(thin)
  xtitle("") xscale(range(2024)) 
  xlabel(2000 2004 2008 2012 2016 2020 2023, nogrid labsize(medium)) 
  ytitle("U.S. Annual Capacity Additions (in Gigawatts)", size(medium))
  yscale(range(0)) ylabel(0(1)7, nogrid angle(0) labsize(medium))
  legend(off) plotregion(style(none)) graphregion(fcolor(white))
  text(2.30 2004 "Tax Credit", size(small) color(`color'))
  text(2.00 2004 "First Introduced", size(small) color(`color'))
  text(1.70 2004 "During 2006", size(small) color(`color'))
  text(3.10 2009 "Credit Became", size(small) color(`color'))
  text(2.80 2009 "Much More Generous", size(small) color(`color'))
  text(2.50 2009 "Starting in 2009", size(small) color(`color'))
  text(4.40 2016.2 "Credit Reduced", size(small) color(`color'))
  text(4.10 2016.2 "From 30% to 26%", size(small) color(`color'))
  text(3.80 2016.2 "Starting in 2020", size(small) color(`color'))
  text(6.50 2018.4 "Credit Increased", size(small) color(`color'))
  text(6.20 2018.4 "Back to 30%", size(small) color(`color'))
  text(5.90 2018.4 "Starting in 2022", size(small) color(`color'))
  || pcarrowi 1.3 2005 0.3 2005.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 2.0 2009 0.5 2009, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 3.7 2018.0 3.35 2019.5, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 6.2 2020.2 6.06 2021.6, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin);
graph export "`root'/figs/SolarInstallations.pdf", replace;


*--------------------------------------------------------*;
*--------------------Electric Vehicles-------------------*;
*--------------------------------------------------------*;
*I copy/pasted from an Argonne PDF with monthly sales for ;
*Argonne National Laboratory, ``Light Duty Electric Drive Vehicles Monthly Sales Updates''
*https://www.anl.gov/esia/light-duty-electric-drive-vehicles-monthly-sales-updates;
*December 2023 not yet available and so 2023 is artificially low;
clear; import excel using "`root'/raw data/EV_Sales.xlsx", first clear; drop G H; rename Year year;
collapse (sum) BEV PHEV HEV TotalLDV, by(year);
gen EV=(BEV+PHEV)/1000000;

*Plot EV Sales;
local color="dkorange";
scatter EV year, title("")
  mcolor(black) msize(large) msymbol(oh) 
  connect(l) lcolor(black) lwidth(thin)
  xtitle("") xscale(range(2024)) 
  xlabel(2010(2)2024, nogrid labsize(medium)) 
  ytitle("U.S. Electric Vehicle Sales (in Millions)", size(medium))
  yscale(range(0)) ylabel(, nogrid angle(0) labsize(medium))
  legend(off) plotregion(style(none)) graphregion(fcolor(white))
  text(0.42 2011 "Tax Credit", size(small) color(`color'))
  text(0.35 2011 "First Introduced", size(small) color(`color'))
  text(0.28 2011 "in 2010", size(small) color(`color'))
  text(0.79 2018 "Credit Phases Out", size(small) color(`color'))
  text(0.72 2018 "for Tesla and", size(small) color(`color'))
  text(0.65 2018 "GM During", size(small) color(`color'))
  text(0.58 2018 "2019 and 2020", size(small) color(`color'))
  text(1.35 2020.0 "Credit Changes", size(small) color(`color'))
  text(1.28 2020.0 "Considerably", size(small) color(`color'))
  text(1.21 2020.0 "With Inflation", size(small) color(`color'))
  text(1.14 2020.0 "Reduction Act", size(small) color(`color'))
  text(1.07 2020.0 "in 2022 and 2023", size(small) color(`color'))
  || pcarrowi 0.22 2010.7 0.05 2010.2, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 0.52 2018.5  0.36 2018.9, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 0.52 2019.0  0.34 2019.8, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 1.00 2021.0 0.95 2021.6, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin)
  || pcarrowi 1.30 2021.5 1.4 2022.6, mlcolor(`color') lcolor(`color') lwidth(thin) mlwidth(thin);
graph export "`root'/figs/EV_Sales.pdf", replace;

